<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'memberfee';
$return=array();
$return['types']=array(
	'1'=>'普通订阅号',
	'2'=>'认证订阅号',
	'3'=>'普通服务号',
	'4'=>'认证服务号'
);
if($_RQ['op']=='member' || $_RQ['op']=='cifee'  || $_RQ['op']=='zhaoshang'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['merchname'])){
		$params['merchname like']='%'.trim($_RQ['merchname']).'%';
		$return['params']['merchname']=$_RQ['merchname'];
	}
	if(!empty($_RQ['realname'])){
		$params['realname like']='%'.trim($_RQ['realname']).'%';
		$return['params']['realname']=$_RQ['realname'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=intval($_RQ['mobile']);
		$return['params']['mobile']=$_RQ['mobile'];
	}
	if($_RQ['status']!=''){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if($_RQ['pcd']){
		$pcd=cfc('tools')->base64_decode($_RQ['pcd'],$_SESSION['base_key_str']);
		$pcd=json_decode($pcd,true);
		$return['params']['pcd']=$pcd;
	}
	if($pcd['province']){
		$params['pcd like']='%'.$pcd['province'].'%';
	}
	if($pcd['city']){
		$params['pcd like']='%'.$pcd['city'].'%';
	}
	if($pcd['district']){
		$params['pcd like']='%'.$pcd['district'].'%';
	}
	if($pcd['street']){
		$params['pcd like']='%'.$pcd['street'].'%';
	}
	$fields=array('id','mid','star','groupid','isrecommand','salecate','cateid','mobile','realname','status','jointime','accounttime','logo','merchname');
    $orderby='star desc, id desc';
	$total='';
	$return['list']=pdo_getslice('jy_merch_user',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	foreach($return['list'] as &$v){
		$v['jointime']=date('Y/m/d H:i:s',$v['jointime']);
		$v['member']=cfc('core')->member_show($v['mid']);
		$v['catename']=pdo_getcolumn('jy_merch_category',array('id'=>$v['cateid'],'uniacid'=>$_SESSION['uniacid']),'catename');
		$v['catename']=$v['catename']?:'';
		if($_RQ['op']=='member'){
			$v['cifee']=pdo_getsum('jy_mlianfee_commission',array('merchid'=>$v['id'],'uniacid'=>$_SESSION['uniacid'],'type'=>0),'money');
		}elseif($_RQ['op']=='cifee'){
			$v['cifee']=pdo_getcolumn('jy_mlianfee_merch',array('merchid'=>$v['id'],'uniacid'=>$_SESSION['uniacid']),'cifee');
		}elseif($_RQ['op']=='zhaoshang'){
			$v['cifee']=pdo_getsum('jy_mlianfee_commission',array('merchid'=>$v['id'],'uniacid'=>$_SESSION['uniacid'],'type'=>2),'money');
		}
		$v['orderprice']=pdo_getsum('jy_weishop_order',array('ispay'=>1,'merchid'=>$v['id'],'uniacid'=>$_SESSION['uniacid']),'price');
	}
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'多商户管理'),
		),
		'list'=>array('data'=>'list','del_one'=>false,'delall'=>false,'edit'=>false,'tip'=>'[<red>温馨提示</red>]:没有地址，经纬度，不在营业时间（休息）的商户，在某些情况下（外卖，附近商户等）可能不会显示出来！','list'=>array(
			array('title'=>'ID/MID','type'=>'img_string',
			'data'=>array(
				array('title'=>'ID：','name'=>'id'),
				array('title'=>'MID：','name'=>'mid')
				)
			),
			array('title'=>'商户信息_Merch','type'=>'img_string','img'=>'logo',
			'data'=>array(
				array('title'=>'名称：','name'=>'merchname'),
				array('title'=>'项目：','name'=>'salecate')
				)
			),
			array('name'=>'groupid','title'=>'商户等级','type'=>'select','options'=>'group','option_title'=>'groupname'),	
			array('title'=>'分类/时间','type'=>'img_string',
			'data'=>array(
				array('title'=>'分类：','name'=>'catename'),
				array('title'=>'入驻：','name'=>'jointime')
				)
			),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status2'),
			array('name'=>'orderprice','title'=>'销售额','type'=>'string')
		)),
		'search'=>array(
			array('name'=>'merchname','width'=>8,'title'=>'商户名称','type'=>'string'),
			array('name'=>'realname','width'=>8,'title'=>'姓名','type'=>'string'),
			array('name'=>'mobile','width'=>8,'title'=>'电话','type'=>'string'),
			array('name'=>'status','width'=>8,'title'=>'状态','type'=>'radio','options'=>'status2'),
			array('type'=>'pcd2','width'=>'40','title'=>'区域','name'=>'pcd','help'=>''),
		)
	);
	if($_RQ['op']=='member'){
		$htmls['list']['list'][]=array('name'=>'cifee','title'=>'带货收益','type'=>'string');
		$htmls['list']['action']=array(
			array('type'=>'modal','op'=>'setmemberfee','title'=>'设置带货收益'),
		);
	}elseif($_RQ['op']=='cifee'){
		$htmls['list']['list'][]=array('name'=>'cifee','title'=>'生态池','type'=>'string');
		$htmls['list']['action']=array(
			array('type'=>'modal','op'=>'setcifee','title'=>'设置生态池抽成'),
		);
	}elseif($_RQ['op']=='zhaoshang'){
		$htmls['list']['list'][]=array('name'=>'cifee','title'=>'培育分佣','type'=>'string');
		$htmls['list']['action']=array(
			array('type'=>'modal','op'=>'setzsfee','title'=>'设置培育分佣'),
		);
	}
	$return['status2']=$this->merch_status;
	$return['group']=pdo_getall('jy_merch_group',array('uniacid'=>$_SESSION['uniacid']),array('id','groupname'),'id');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='setmemberfee'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$data=array(
			'memberrate'=>$post['memberrate'],
		);
		$id=intval($post['id']);
		if($id){
			$this->update('merch',$data,array('id'=>$id));
		}else{
			$data['uniacid']=$_SESSION['uniacid'];
			$data['merchid']=intval($post['merchid']);
			$this->insert('merch',$data);
		}
		exi('设置成功！','','goback');
	}
	$merchid=intval($_RQ['id']);
	if($merchid){
		$item=pdo_get('jy_mlianfee_merch',array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid']));
		$item['merchid']=$item['merchid']?:$merchid;
	}else{
		$item=array('merchid'=>$merchid);
	}
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'desc'=>'设置带货分佣',
		'edit'=>array(
			array('name'=>'memberrate','title'=>'带货分佣','type'=>'string','help'=>'填写数字表示固定佣金，填写%，表示按百分比计算佣金'),	
		),
	);
	exi($return);
}
if($_RQ['op']=='setcifee'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$data=array(
			'cirate'=>$post['cirate'],
		);
		$id=intval($post['id']);
		if($id){
			$this->update('merch',$data,array('id'=>$id));
		}else{
			$data['uniacid']=$_SESSION['uniacid'];
			$data['merchid']=intval($post['merchid']);
			$this->insert('merch',$data);
		}
		exi('设置成功！','','goback');
	}
	$merchid=intval($_RQ['id']);
	if($merchid){
		$item=pdo_get('jy_mlianfee_merch',array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=array();
	}
	$item['merchid']=$item['merchid']?:$merchid;
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'desc'=>'设置生态池抽成',
		'edit'=>array(
			array('name'=>'cirate','title'=>'带货分佣','type'=>'string','help'=>'填写数字表示固定佣金，填写%，表示按百分比计算佣金'),	
		),
	);
	exi($return);
}
if($_RQ['op']=='setzsfee'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$data=array(
			'zsrate'=>$post['zsrate'],
		);
		$id=intval($post['id']);
		if($id){
			$this->update('merch',$data,array('id'=>$id));
		}else{
			$data['uniacid']=$_SESSION['uniacid'];
			$data['merchid']=intval($post['merchid']);
			$this->insert('merch',$data);
		}
		exi('设置成功！','','goback');
	}
	$merchid=intval($_RQ['id']);
	if($merchid){
		$item=pdo_get('jy_mlianfee_merch',array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=array();
	}
	$item['merchid']=$item['merchid']?:$merchid;
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'desc'=>'设置培育分佣',
		'edit'=>array(
			array('name'=>'zsrate','title'=>'培育分佣','type'=>'string','help'=>'填写数字表示固定佣金，填写%，表示按百分比计算佣金'),	
		),
	);
	exi($return);
}
?>